package com.cwvs.cat.adapter;

import java.util.List;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.cwvs.cat.MyActiveManageEditActivity;
import com.cwvs.cat.R;
import com.cwvs.cat.bean.ActiveContent;
import com.cwvs.cat.myview.CustomTextView;

public class MyActivePublishAdapter extends BaseAdapter {

	private Context mContext;
	private LayoutInflater mInflater = null;
	private ViewHolder holder = null;
	private List<ActiveContent> mList;

	public MyActivePublishAdapter(Context context, List<ActiveContent> list) {
		this.mContext = context;
		this.mInflater = LayoutInflater.from(context);
		mList = list;

	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return mList.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return mList.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub

		if (convertView == null) {
			convertView = mInflater.inflate(
					R.layout.item_list_my_active_publish, null);
			holder = new ViewHolder();
			holder.title1 = (CustomTextView) convertView.findViewById(R.id.title_1);
			holder.txt_active_manager_edit = (CustomTextView) convertView
					.findViewById(R.id.txt_active_manager_edit);
			holder.actmyadd_time = (CustomTextView) convertView
					.findViewById(R.id.actmyadd_time);
			holder.actmyadd_location = (CustomTextView) convertView
					.findViewById(R.id.actmyadd_location);
			holder.actmyadd_title = (CustomTextView) convertView
					.findViewById(R.id.actmyadd_title);
			holder.txt_active_manager_edit
					.setOnClickListener(new OnClickListener() {
						@Override
						public void onClick(View v) {
							// TODO Auto-generated method stub
							Intent intent = new Intent();
							intent.setClass(mContext,MyActiveManageEditActivity.class);
							intent.putExtra("json",mList.get(position).toJson().toString());
							mContext.startActivity(intent);
						}
					});
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		
	//	String[] data = mList.get(position).begin_time.split(" ");
	//	String y = data[0];
	//	String t = data[1];
	//	String[] a = y.split("-");
	//	String[] b = t.split(":");
		holder.title1.setText(mList.get(position).begin_time);
		holder.actmyadd_time.setText(mList.get(position).begin_time);
		holder.actmyadd_location.setText(mList.get(position).location);
		holder.actmyadd_title.setText(mList.get(position).categoryname);
		return convertView;
	}

	class ViewHolder {
		public CustomTextView title1, txt_active_manager_edit,actmyadd_time,actmyadd_location,actmyadd_title;

	}

}
